# -*- encoding: UTF-8 -*-
'''
@File    :  recursion.py
@Time    :  2021/05/16 10:39:20
@Author  :  Kearney
@Contact :  191615342@qq.com
@Desc    :  递归
'''
import os


def factorial_for(number):
    """ for 循环求阶乘，未作异常处理 """
    sum = 1  # 阶乘结果
    for i in range(1, number + 1):
        sum = sum * i
    return sum


def factorial_rec(number):
    """ 递归求阶乘，未作异常处理 """
    if number < 3:  # 基准情形：1、2
        return number
    else:
        return number * factorial_rec(number - 1)  # 递归调用


print("5! = ", factorial_for(5))
print("5! = ", factorial_rec(5))


def find_files(path):
    filelist = os.listdir(path)

    for filename in filelist:
        filepath = os.path.join(path, filename)
        if os.path.isdir(filepath):  # 是目录就递归调用自身
            find_files(filepath)
        else:  # 基准情形，文件
            print(filepath)


find_files('./')  # 当前目录
# find_files('../')  # 当前目录的上一级目录，隐藏文件也会遍历
